﻿namespace NumericalSolution {
  abstract class Poisson2DFV {
    protected int p_numberOfControlVolumes;
    protected double p_deltax;
    protected double p_deltay;

    public int NumberOfControlVolumes {
      get { return p_numberOfControlVolumes; }
      set {
        p_numberOfControlVolumes = value;
        p_deltax = 1.0 / p_numberOfControlVolumes;
        p_deltay = 1.0 / p_numberOfControlVolumes;
      }
    }

    public double DeltaX {
      get { return p_deltax; }
    }

    public double DeltaY {
      get { return p_deltay; }
    }

    public abstract void Prepare();
    public abstract ROResult2D Solve();

    protected int index(int i, int j) {
      return j * p_numberOfControlVolumes + i;
    }

    public double posx(int i) {
      return p_deltax / 2.0 + i * p_deltax;
    }

    public double posy(int j) {
      return p_deltay / 2.0 + j * p_deltay;
    }

    protected double f(double x, double y) {
      return -2 * x * (x - 1) - 2 * y * (y - 1);
    }

  }
}
